function quickSort(arr) {
  const len = arr.length-1
  if(len<=0) return arr
  const middleIndex = Math.floor(len/2)
  const leftArr = []
  const rightArr = []
  const middle = arr.splice(middleIndex, 1)
  // const rightArr = []
  for(let i=0; i <= arr.length; i++) {
    if(arr[i] <= middle) leftArr.push(arr[i])
    if(arr[i] > middle) rightArr.push(arr[i])
  }
return [...quickSort(leftArr), middle, ...quickSort(rightArr)]
}

console.log(quickSort([2,3,567,34,34,32,65,87,9,89,54,23,32,43,65,9,0,7,5,23,1]))